package com.online.music.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.online.music.common.Result;
import com.online.music.utils.UserContextUtil;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

import com.online.music.service.ICommentReportService;
import com.online.music.entity.po.CommentReport;

import org.springframework.web.bind.annotation.RestController;


/**
 * @Author: Leno
 * @Date: 2025-02-10
 * @Description: commentReport接口
 */
@RequiredArgsConstructor
@Slf4j
@Tag(name = "commentReport接口")
@RestController
@RequestMapping("/comment-report")
public class CommentReportController {

    private final ICommentReportService commentReportService;

    @Operation(summary = "查询所有CommentReport")
    @GetMapping
    public Result<List<CommentReport>> findAll() {
        return Result.success(commentReportService.list());
    }

    @Operation(summary = "根据id查询CommentReport")
    @GetMapping("/{id}")
    public Result<CommentReport> findOne(@PathVariable Long id) {
        return Result.success(commentReportService.getById(id));
    }

    @Operation(summary = "根据分页查询CommentReport")
    @GetMapping("/page")
    public Result<Page<CommentReport>> findPage(@RequestParam Integer pageNum, @RequestParam Integer pageSize,
                                                CommentReport commentReport) {
        return commentReportService.findPage(pageNum, pageSize, commentReport);
    }

    @Operation(summary = "添加或修改CommentReport")
    @PostMapping
    public Result<Boolean> save(@RequestBody CommentReport commentReport) {
        commentReport.setUserId(UserContextUtil.getUserId());
        CommentReport one = commentReportService.lambdaQuery()
                .eq(CommentReport::getCommentId, commentReport.getCommentId())
                .eq(CommentReport::getUserId, UserContextUtil.getUserId())
                .one();
        if (one != null) {
            commentReport.setId(one.getId());
        }
        return Result.success(commentReportService.saveOrUpdate(commentReport));
    }

    @Operation(summary = "根据id批量删除CommentReport")
    @DeleteMapping("/del/batch")
    public Result<String> deleteBatch(@RequestBody List<Long> ids) {
        return commentReportService.deleteBatch(ids);
    }

}
